<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>core - Unicorn Tests</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">

<link type="text/css" rel="stylesheet" href="../yui/logger/assets/logger.css" />     
<link type="text/css" rel="stylesheet" href="../assets/testlogger.css" />
<script type="text/javascript" src="../yui-base.source.js"></script>
<script type="text/javascript" src="../yui/logger/logger.js"></script>
<script type="text/javascript" src="../yui/yuitest/yuitest.js"></script>

<script type="text/javascript" src="../build/core/Unicorn.source.js"></script>
<script type="text/javascript" src="../build/core/lang.source.js"></script>
</head>

<body>
<h1>Unicorn Test Page</h1>
<p>This page contains tests being run by test suite, the results of which<br />
are output in the logger to the right. <br />View the source to see how it's done.</p>
<p><input type="button" value="Run Tests" id="btnRun" /></p>

<script type="text/javascript">
(function() {

    var Dom = Unicorn.util.Dom,
        Assert = YAHOO.util.Assert,
        ObjectAssert = YAHOO.util.ObjectAssert,
        ArrayAssert = YAHOO.util.ArrayAssert;
     
    var suite = new YAHOO.tool.TestSuite("testSuite");
    
    suite.add(new YAHOO.tool.TestCase({
        
        //name of the test case
        name: "Unicorn TestCase",

        //extra information about tests
        _should: {
            //tests with these names should fail
            fail : { test_to_fail: true },
            
            //tests with these names should throw an error
            error : { },
            
            //ignore these tests
            ignore : { }
        },

        testCreateNamespace: function () {

            // set up Unicorn.my.namespace
            var ns = Unicorn.namespace("my.namespace");

            // use the returned reference, assign a value
            ns.test = "taobao_my_namespace_test";

            // check for the assigned value using the full path
            Assert.areEqual(Unicorn.my.namespace.test, "taobao_my_namespace_test", "The namespace was not set up correctly");

            // assign a value to my to test that it doesn't get wiped out
            Unicorn.my.test = "taobao_my_test";

            // create another namespace on my
            var ns2 = Unicorn.namespace("my.namespace2");

            // make sure my stays the same
            Assert.areEqual(Unicorn.my.test, "taobao_my_test", "The namespace was obliterated");
        },
        
        testStringPrototype: function() {
        	
        	// trim
        	var s = '  foo bar   ';
        	Assert.areEqual(s.trim(), 'foo bar');
        	
        	// stripTags
        	var s2 = 'a <a href="#">link</a>';
        	Assert.areEqual(s2.stripTags(), 'a link');
         	
         	var s3 = 'a <a href="#"<div class="bad">link</a>';
        	Assert.areEqual(s3.stripTags(), 'a link');
        	       	
        },
        
        testArrayPrototype: function() {
        	
	        // indexOf
	        var o = { };
	        var arr = [1, 'a', o, null, ''];
	        Assert.areEqual(arr.indexOf(1), 0);
	        Assert.areEqual(arr.indexOf('a'), 1);
	        Assert.areEqual(arr.indexOf(o), 2);
	        Assert.areEqual(arr.indexOf(null), 3);
	        Assert.areEqual(arr.indexOf(''), 4);
	        
	        Assert.areEqual(arr.indexOf('a', 1), 1);
	        Assert.areEqual(arr.indexOf('a', 2), -1);
	        Assert.areEqual(arr.indexOf('a', -1), -1);
	        Assert.areEqual(arr.indexOf('a', -100), 1);
	        Assert.areEqual(arr.indexOf('a', -4), 1);
	        
	        Assert.areEqual(arr.indexOf('b'), -1);
	        
	        // forEach
	        var arr2 = [1, 2, 3, 4];
	        var arr3 = [];
	        arr2.forEach(function(each) { arr3.push(each * 2); });
	        Assert.areEqual(arr3.toString(), [2, 4, 6, 8].toString());
        },

        test_to_fail: function (){
            Assert.isNull('not null');
            Assert.isTrue([1, 2].forEach('f'));
        }
        
    }));
     
    YAHOO.util.Event.onDOMReady(function (){
        //create the logger
        var logger = new YAHOO.tool.TestLogger();
        
        //add the tests
        YAHOO.tool.TestRunner.add(suite);
        
        //add event handler
        YAHOO.util.Event.addListener("btnRun", "click", function() { location.replace(location.href); });

        if (parent && parent != window) {
            YAHOO.tool.TestManager.load();
        } else {
            YAHOO.tool.TestRunner.run();
        }
    });
    
})();
</script>
</body>
</html>
